package org.hongzhisoft.dis.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hongzhisoft.dis.service.RoleService;
import org.hongzhisoft.dis.service.impl.RoleServiceImpl;

/**
 * 角色状态操作处理类
 * @author HongChengzhi
 *
 */
@WebServlet("/role/status")
public class RoleStatusServlet extends HttpServlet {
	private final static int ENABLED = 0;
	private final static int DISCONTINUED = 1;

    /**
     * 
     */
    private static final long serialVersionUID = 1L;
    private RoleService roleService = new RoleServiceImpl();

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
            throws ServletException, IOException {

        int role_id =  Integer.parseInt(req.getParameter("role_id"));
        String role_name =  req.getParameter("role_name");
        int status = Integer.parseInt(req.getParameter("status"));
        
        try {
        	if (status == ENABLED) {
        		roleService.statusChangeRole(DISCONTINUED, role_id);
			}
        	if (status == DISCONTINUED) {
        		roleService.statusChangeRole(ENABLED, role_id);
			}
        	
             req.setAttribute("role_name", role_name);
             req.getRequestDispatcher("/statusrole_success.jsp").forward(req, resp);
             
        } catch (Exception e) {
            throw new ServletException(e);
        }
        


    }

}
